package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.common.util.KiteListUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.*;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 营销渠道：短信和外呼 100000727(短信),100000756(外呼)
 */
public class SalesWayAttrHandler extends AbstractAttrHandler<KiteInst, AttrData> {
    @Autowired
    private IQuerySceneInstService querySceneInstService;
    @Override
    public void set(KiteAttr attr, KiteInst inst, String value, AttrData data) {
        super.set(attr, inst, value, data);
        String sceneInstId = data.getSceneInstId();
        // 获取所有的主套餐
        List<KiteOfferInst> kiteOfferInsts = querySceneInstService.listMainOfferInsts(sceneInstId);
        //业务开通 200000000001321(批量营销),200000000001320(失联复联)
        String offerId = "";
        if(KiteListUtils.isNotEmpty(kiteOfferInsts)){
           //批量营销
           List<KiteOfferInst> plyxlist = kiteOfferInsts.stream().filter(it->KiteStringUtils.equals("200000000001321",it.getSpecId())).collect(Collectors.toList());
           //失联复联
           List<KiteOfferInst> slfllist = kiteOfferInsts.stream().filter(it->KiteStringUtils.equals("200000000001320",it.getSpecId())).collect(Collectors.toList());
           if(KiteListUtils.isNotEmpty(plyxlist)){
               offerId = plyxlist.get(0).getSpecId();
           }else if(KiteListUtils.isNotEmpty(slfllist)){
               offerId = slfllist.get(0).getSpecId();
           }
        }
        //标签筛选数据服务费（元）
        KiteAttr bqsxsjfwfAttr = inst.getAttr("200001006");
        //IMEI数据服务费（元）
        KiteAttr imeisjfwfAttr = inst.getAttr("200001007");
        //短信数据服务费-信用卡（元）
        KiteAttr dxsjfwfxykAttr = inst.getAttr("200001010");
        //短信数据服务费-非信用卡（元）
        KiteAttr dxsjfwffxykAttr = inst.getAttr("200001011");
        //身份验证数据费-保险行业（元）
        KiteAttr sfyzsjfwfbxhyAttr = inst.getAttr("200001008");
        //身份验证数据费-非保险行业（元）
        KiteAttr sfyzsjfwffbxhyAttr = inst.getAttr("200001009");
        //初始化全显示
        if(null!=bqsxsjfwfAttr){
            bqsxsjfwfAttr.setShowType("D");
        }
        if(null!=imeisjfwfAttr){
            imeisjfwfAttr.setShowType("D");
        }
        if(null!=dxsjfwfxykAttr){
            dxsjfwfxykAttr.setShowType("D");
        }
        if(null!=dxsjfwffxykAttr){
            dxsjfwffxykAttr.setShowType("D");
        }
        if(null!=sfyzsjfwfbxhyAttr){
            sfyzsjfwfbxhyAttr.setShowType("D");
        }
        if(null!=sfyzsjfwffbxhyAttr){
            sfyzsjfwffbxhyAttr.setShowType("D");
        }
        if(KiteStringUtils.isNotBlank(offerId) && KiteStringUtils.equals("200000000001321",offerId)){
            //批量营销
            if (attr.getValue().contains("100000727") && !attr.getValue().contains("100000756")) {
                //只选短信
                if(null!=bqsxsjfwfAttr){
                    bqsxsjfwfAttr.setShowType("E");
                }
                if(null!=imeisjfwfAttr){
                    imeisjfwfAttr.setShowType("E");
                }
                if(null != sfyzsjfwfbxhyAttr){
                    sfyzsjfwfbxhyAttr.setShowType("E");
                }
                if(null != sfyzsjfwffbxhyAttr){
                    sfyzsjfwffbxhyAttr.setShowType("E");
                }
            }else if(attr.getValue().contains("100000727") && attr.getValue().contains("100000756")){
                //短信和外呼全选
                if(null != sfyzsjfwfbxhyAttr){
                    sfyzsjfwfbxhyAttr.setShowType("E");
                }
                if(null != sfyzsjfwffbxhyAttr){
                    sfyzsjfwffbxhyAttr.setShowType("E");
                }
            }else if(attr.getValue().contains("100000756") && !attr.getValue().contains("100000727")) {
                //只选外呼
                if(null != dxsjfwfxykAttr){
                    dxsjfwfxykAttr.setShowType("E");
                }
                if(null != dxsjfwffxykAttr){
                    dxsjfwffxykAttr.setShowType("E");
                }
                if(null != sfyzsjfwfbxhyAttr){
                    sfyzsjfwfbxhyAttr.setShowType("E");
                }
                if(null != sfyzsjfwffbxhyAttr){
                    sfyzsjfwffbxhyAttr.setShowType("E");
                }
            }
        }else if(KiteStringUtils.isNotBlank(offerId) && KiteStringUtils.equals("200000000001320",offerId)){
            //失联复联
            if (attr.getValue().contains("100000727") && !attr.getValue().contains("100000756")) {
                //只选短信
                if(null != bqsxsjfwfAttr){
                    bqsxsjfwfAttr.setShowType("E");
                }
                if(null != imeisjfwfAttr){
                    imeisjfwfAttr.setShowType("E");
                }
                if(null != sfyzsjfwfbxhyAttr){
                    sfyzsjfwfbxhyAttr.setShowType("E");
                }
                if(null != sfyzsjfwffbxhyAttr){
                    sfyzsjfwffbxhyAttr.setShowType("E");
                }
            }else if(attr.getValue().contains("100000727") && attr.getValue().contains("100000756")){
                //短信和外呼全选
                if(null != bqsxsjfwfAttr){
                    bqsxsjfwfAttr.setShowType("E");
                }
                if(null != imeisjfwfAttr){
                    imeisjfwfAttr.setShowType("E");
                }
            }else if(attr.getValue().contains("100000756") && !attr.getValue().contains("100000727")) {
                //只选外呼
                if(null != bqsxsjfwfAttr){
                    bqsxsjfwfAttr.setShowType("E");
                }
                if(null != imeisjfwfAttr){
                    imeisjfwfAttr.setShowType("E");
                }
                if(null != dxsjfwfxykAttr){
                    dxsjfwfxykAttr.setShowType("E");
                }
                if(null != dxsjfwffxykAttr){
                    dxsjfwffxykAttr.setShowType("E");
                }
            }
        }


    }
}
